home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / gnucdiff / normal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-26  |  2.3 KB  |  73 lines

  1. /* Normal-format output routines for GNU DIFF.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU DIFF General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU DIFF, but only under the conditions described in the
  15. GNU DIFF General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU DIFF so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. #include "diff.h"
  23.  
  24. void print_normal_hunk ();
  25. void print_number_range ();
  26. struct change *find_change ();
  27.  
  28. /* Print the edit-script SCRIPT as a normal diff.
  29.    INF points to an array of descriptions of the two files.  */
  30.  
  31. void
  32. print_normal_script (script)
  33.      struct change *script;
  34. {
  35.   print_script (script, find_change, print_normal_hunk);
  36. }
  37.  
  38. /* Print a hunk of a normal diff.
  39.    This is a contiguous portion of a complete edit script,
  40.    describing changes in consecutive lines.  */
  41.  
  42. void
  43. print_normal_hunk (hunk)
  44.      struct change *hunk;
  45. {
  46.   int first0, last0, first1, last1, deletes, inserts;
  47.   register int i;
  48.  
  49.   /* Determine range of line numbers involved in each file.  */
  50.   analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
  51.   if (!deletes && !inserts)
  52.     return;
  53.  
  54.   /* Print out the line number header for this hunk */
  55.   print_number_range (',', &files[0], first0, last0);
  56.   fprintf (outfile, "%c", change_letter (inserts, deletes));
  57.   print_number_range (',', &files[1], first1, last1);
  58.   fprintf (outfile, "\n");
  59.  
  60.   /* Print the lines that the first file has.  */
  61.   if (deletes)
  62.     for (i = first0; i <= last0; i++)
  63.       print_1_line ("<", &files[0].linbuf[i]);
  64.  
  65.   if (inserts && deletes)
  66.     fprintf (outfile, "---\n");
  67.  
  68.   /* Print the lines that the second file has.  */
  69.   if (inserts)
  70.     for (i = first1; i <= last1; i++)
  71.       print_1_line (">", &files[1].linbuf[i]);
  72. }
  73.